// #packager-optimize

(function() {

    /**
     * Used to proxy drop area element.
     */
    var DropProxy = function() {

        this.CLASS_NAME = 'drop-proxy';

        this.AREA_CLASS_NAME_POSTFIX = '-area';

        this.areaLayout = {
            LEFT : 'left',
            MIDDLE : 'middle',
            RIGHT : 'right'
        };

        /**
         * Proxy dom element.
         */
        this.domElement = null;

        this.hightlightedArea = null;

        this.areas = [];

        /**
         * Shows the proxy object.
         */
        this.show = function() {
            this.domElement.style.display = 'block';
        };

        /**
         * Hides the proxy object.
         */
        this.hide = function() {
            this.domElement.style.display = 'none';
        };

        /**
         * Sets the proxy objects size equals to passed parameters.
         */
        this.setSize = function(width, height) {
            this.domElement.style.width = width + 'px';
            this.domElement.style.height = height + 'px';
        };

        /**
         * Sets the proxy objects offset equals to passed parameters.
         */
        this.setOffset = function(left, top) {
            this.domElement.style.left = left + 'px';
            this.domElement.style.top = top + 'px';
        };

        this.addArea = function(layout) {
            var area = document.createElement('div');
            area.className = layout + this.AREA_CLASS_NAME_POSTFIX;
            this.areas.push(this.domElement.appendChild(area));
        };

        this.hightlightArea = function(areaClassName) {
            this.hightlightedArea = null;

            for (var i = 0; i < this.areas.length; ++i) {
                var currentArea = this.areas[i];

                if ( currentArea.className === areaClassName ) {
                    currentArea.style.backgroundColor = 'black';
                    this.hightlightedArea = currentArea;
                } else {
                    currentArea.style.backgroundColor = 'white';
                }
            }
        };

        this.getHightlightedAreaLayout = function() {
            if ( !this.hightlightedArea ) return null;

            var result = (new RegExp('([A-z]+)-area')).exec(this.hightlightedArea.className);
            return result[1];
        };

        this.createAreas = function() {
            for (var i in this.areaLayout) {
                this.addArea(this.areaLayout[i]);
            }
        };

        /**
         * Creates proxy dom element.
         */
        this.createDomElement = function() {
            this.domElement = document.createElement('div');
            this.domElement.className = this.CLASS_NAME;

            this.createAreas();

            document.body.appendChild(this.domElement);
        };

        /**
         * Initialize instance.
         */
        this.initialize = function() {
            this.createDomElement();
        };

    };

    juliet.registerModule('juliet.ui.dragAndDrop', 'DropProxy-0.1', DropProxy);

})();
